<template>
	<view class="ljapp doctor">
		<view class="content">
			<view class="px20">
				<view class="card">
					<view class="lj-consultation-list">
						<view class="item" v-for="(item,index) in group.list" :key="index">
							<view class="info u-flex">
								<image class="avatar" :src="$base.img(item.user_headimgurl)" mode="aspectFill"></image>
								<view class="u-flex-1">
									<view class="tit u-flex u-flex-between u-flex-y-center">
										<view class="u-flex u-flex-fill">
											<view class="name">{{item.user_the_patient_info.name}}</view>
											<view class="sex">{{item.user_the_patient_info.sex==1?'男':'女'}}</view>
											<view class="age">{{item.user_the_patient_info.age}}岁</view>
											<view class="tag" :class="{v:item.type=='sp', r:item.type=='report'}">
												<block v-if="item.type=='tw'">图文</block>
												<block v-else-if="item.type=='sp'">视频</block>
												<block v-else-if="item.type=='report'">报告</block>
											</view>
										</view>
										<view class="price">￥{{item.money}}</view>
									</view>
									<view class="con u-line-2">
										<view v-if="item.type!='report'"><text>病情描述</text>：{{item.content}}</view>
									</view>
									<view class="u-flex u-flex-between u-flex-y-center">
										<view class="time u-flex-1">
											<text>下单日期</text>：{{$u.timeFormat(item.createtime,'yyyy年mm月dd日 hh:MM')}}</view>
										<view class="btn-img btn-receive">
											<image src="/static/lj/common/capsule_317.png" mode="aspectFill"></image>
											<view class="tit" @click="Onjump(item)">{{item.typename}}</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>

					<lj-empty v-if="group.loaded&&group.list.length<=0">暂无订单</lj-empty>
					<view v-else>
						<u-loadmore
							:status="loading?'loading':(group.loaded?'nomore':'loadmore')"
							fontSize="28rpx"
							color="#d9d9d9"
							nomoreText="已加载全部"
							marginTop="30rpx"
							marginBottom="0"
							@loadmore="getList"
						></u-loadmore>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				group:{
					page: 1,
					limit: 10,
					list: [],
					loaded: false
				},
				loading: false,
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				this.group.page = 1
				this.group.list = []
				this.group.loaded = false
				this.loading = false

				this.getList();
			},

			getList() {
				var that = this,group = that.group;
				if(that.loading || group.loaded) return;

				that.loading = true

				this.$Http({
					url: 'doctorlistConsultation3Order',
					data: {
						page: group.page,
						limit: group.limit,
					},
				}).then(res=>{
					if(res.code == 1){
						var list = res.data;
						group.loaded = list.length < group.limit;
						group.page ++;

						list.forEach(item => {
							if(item.user_the_patient_info) item.user_the_patient_info.age = this.$base.Onage(item.user_the_patient_info.birthday)

							if (item.pay_status == 2) {
								if (item.status == 'normal') {
									item.typename = '待支付'
								}
								if (item.status == 'cancel') {
									item.typename = '已取消'
								}
								item.status_is = false
							}
							if (item.pay_status == 1) {
								item.status_is = true
								if (item.status == 'normal') {
									item.typename = '去接诊'
								}
								if (item.status == 'refund') {
									item.typename = '已退款'
									item.status_is = false
								}
								if (item.status == 'refuse_patient') {
									item.typename = '拒绝接诊'
								}
								if (item.status == 'patient') {
									item.typename = '接诊中'
								}
								if (item.status == 'end') {
									item.typename = '接诊完成'
								}
								if (item.status == 'comment') {
									item.typename = '已评价'
								}
							}
						})
						group.list = group.list.concat(list);
					}

					that.loading = false
				}).catch(()=>{
					that.loading = false
				});
			},
			onReachBottom(){
				this.getList()
			},

			goto(e){
				uni.navigateTo({
					url: e
				})
			},
			Onjump(e) {
				if(e.type=='tw'){
					uni.navigateTo({
						url: '/pagesA/message/chat?isDoc=1&cate=text&orderno='+e.order_code
					})
				}else if(e.type=='sp'){
					uni.navigateTo({
						url: '/pagesA/message/chat?isDoc=1&cate=video&orderno='+e.order_code
					})
				}else if(e.type=='report'){
					uni.navigateTo({
						url: '/pagesA/message/chat?isDoc=1&cate=report&orderno='+e.order_code
					})
				}
			}
		}
	}
</script>

<style lang="less">
	@import '@/pages/style.less';

	.doctor .content .card{
		padding: 0;
		margin-top: 0;
		background-color: transparent;

		.lj-consultation-list{
			.item{
				background-color: #fff;
			}
		}
	}
</style>
